package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "PersonageHtml",value = {"/html/admin/*"})
public class PersonageHtml implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        if(PersonagePort.validationCookie(req,"ROOT","SID")){
            chain.doFilter(req,resp);
            return;
        }

        if(PersonagePort.validationCookie(req,"ID","SID")){
            chain.doFilter(req, resp);
            return;
        }

        ((HttpServletResponse)resp).sendRedirect("/home/login.html");
    }
}
